from collections import deque

def search(lines, pattern, history=5):
    previous_lines = deque(maxlen=history)
    for li in lines:
        if pattern in li:
            yield li, previous_lines
        previous_lines.append(li)

def squares(n):
    for i in range(n):
        yield i * i

# 直接使用 for 循环
for square in squares(5):
    print(square)  # 输出：0, 1, 4, 9, 16